package com.demo.dao;

import com.demo.dao.mapper.PersonMapper;
import com.demo.dao.mode.PersonInfo;
import org.apache.ibatis.session.SqlSession;
import sun.jvm.hotspot.asm.Register;

public class PersonDao extends BaseDao{
    private static final String ENVIRONMENT_HOMER = "HOMER";
    private static final String ENVIRONMENT_CU = "CU";

    public PersonInfo getPersonInfo(String personId){
        PersonInfo personInfo = null;
        Register register = null;
        PersonDao personDao = new PersonDao();
        personInfo = personDao.getPersonByPersonId(personId);
        RegisterDao registerDao = new RegisterDao();
        register = registerDao.checkRegister(personId);
        personInfo.setRegister(register);
        return personInfo;
    }

    public PersonInfo getPersonByPersonId(String personId) {
        PersonInfo person = null;

        try (SqlSession session = openSession(ENVIRONMENT_HOMER);){
            PersonMapper mapper = session.getMapper(PersonMapper.class);
            person = mapper.selectPersonByPersonId(personId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return person;
    }

    public String selectPersonCuid(String personId) {
        String cuid = null;

        try (SqlSession session = openSession(ENVIRONMENT_CU)){
            PersonMapper mapper = session.getMapper(PersonMapper.class);
            cuid = mapper.selectPersonCuid(personId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cuid;
    }
}
